var app = getApp()
var util = require("../../utils/util.js")
var clerkModel = require("../../model/clerkModel.js")
var userUtil = require("../../utils/userUtil.js")
var dialUtil = require("../../utils/dialUtil.js")
var settingModel = require("../../model/settingModel.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    records: [], //当前预约记录
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      clerk: app.data.clerk
    })
    this.init()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  init() {
    var that = this
    util.showLoading("加载中")
    clerkModel.getTodayAppointment(this.data.clerk.id, res => {
      wx.hideLoading()
      if (res.status == 1) {
        util.failToast(res.msg)
        return
      }
      that.setData({
        records: res.data
      })
    })
    settingModel.getStore(res => {
      if (res.status == 1) {
        util.failToast(res.msg)
        return
      }
      that.setData({
        store: res.data
      })
    })
  },
  //快捷拨号
  bindDial() {
    var phone = this.data.store.phone
    dialUtil.dial(phone)
  },
  navToAppointment() {
    if (!userUtil.isLogin()) {
      userUtil.toLogin()
      return
    }
    var clerk = this.data.clerk
    var temp = {
      uid: clerk.id,
      uname: clerk.username,
      uimgUrl: clerk.imgUrl
    }
    app.data.tempClerk = temp
    wx.navigateTo({
      url: '../clerk_appointment/clerk_appointment'
    })
  }
})